package com.demo.app.module.user;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/user")
public class UserController {
	
	public static Map<String,RoleInfo> map = new HashMap<String,RoleInfo>();
	
	@RequestMapping("/userlist")
	public String userlist(Model model) {
		List<RoleInfo> list = new ArrayList<RoleInfo>();
		for(Map.Entry<String, RoleInfo> entry: map.entrySet()) {
			list.add(entry.getValue());
		}
		
		model.addAttribute("roles",list);
		model.addAttribute("size",list.size());
		
		return "user/admin-role";
	}
	
	@RequestMapping("/adduser")
	public String adduser(HttpServletRequest request,Model model) {
		
		String id = request.getParameter("id");
		if("".equals(id) || null == id)
		return "/user/admin-role-add";
		else
		{
			RoleInfo role = map.get(id);
			model.addAttribute("role",role);
			return "/user/admin-role-add";
		}
	}
	@RequestMapping("/save")
	@ResponseBody
	public void saveRole(RoleInfo role) {
		
				String key = String.valueOf(System.currentTimeMillis());
				role.setId(key);
				map.put(key, role);
	}
}
